#pragma once
#include "glad/glad.h"
#include "GLShader.h"
#include <iostream>
class GLMesh final {
public:
	GLMesh(const uint32_t* indices, uint32_t indicesSize, const float* vertexData, uint32_t verticesSize)
		: numIndices_(indicesSize / sizeof(uint32_t))
		, bufferIndices_(indicesSize, indices, 0)
		, bufferVertices_(verticesSize, vertexData, 0) 
	{
		glCreateVertexArrays(1, &vao_);
		glVertexArrayElementBuffer(vao_, bufferIndices_.getHandle());
	}

	void draw() const {
		glBindVertexArray(vao_);
		glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, bufferVertices_.getHandle());
		glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(numIndices_), GL_UNSIGNED_INT, nullptr);
	}

	~GLMesh() {
		glDeleteVertexArrays(1, &vao_);
	}
	GLMesh() = default;
private:
	GLuint vao_;
	uint32_t numIndices_;

	GLBuffer bufferIndices_;
	GLBuffer bufferVertices_;
};